Interactive Plot Examples

Manhattan plots

  • The required columns to create a manhattan plot are the chromosome, base-pair position and p-value. By default, the manhattanly function assumes these columns are named CHR, BP and P (but these can be specified by the user if they are different)

Create an interactive manhattan plot using one command:

#install.packages("manhattanly")
# load the manhattanly library
library(manhattanly)
## See example usage at http://sahirbhatnagar.com/manhattanly/
manhattanly(
  subset(
    HapMap, CHR %in% 4:7),
  snp = "SNP",
  gene = "GENE")
  • We can also highlight SNPs of interest using the highlight argument. This package comes with a list of SNPs of interest called significantSNP (see help(significantSNP) for more details). To highlight these SNPs we simply pass this vector to the highlight argument (note that these SNPs need to be present in the “SNP” column of your data):
manhattanly(subset(HapMap, CHR %in% 4:7), snp = "SNP", gene = "GENE", highlight = significantSNP)
  • You can add up to 4 annotations. In the following plot we add the snp, gene, the distance to the nearest gene and the effect size:
manhattanly(subset(HapMap, CHR %in% 4:7), snp = "SNP", gene = "GENE",
            annotation1 = "DISTANCE", annotation2 = "EFFECTSIZE",
            highlight = significantSNP)
  • The annotations in the previous plots only appear when we hover the mouse over the point. Once we have identified a SNP, or a few SNPs of interest we want to explicitly show the annotation information and save the plot. The output of the manhattanly function is an object which can be further manipulated using the %>% operator from the magrittr package:
library(magrittr)

p <- manhattanly(subset(HapMap, CHR %in% 4:7), snp = "SNP", gene = "GENE",
            annotation1 = "DISTANCE", annotation2 = "EFFECTSIZE",
            highlight = significantSNP)

# get the x and y coordinates from the pre-processed data
plotData <- manhattanr(subset(HapMap, CHR %in% 4:7), snp = "SNP", gene = "GENE")[["data"]]

# annotate the smallest p-value
annotate <- plotData[which.min(plotData$P),]

# x and y coordinates of SNP with smallest p-value
xc <- annotate$pos
yc <- annotate$logp

p %>% plotly::layout(annotations = list(
  list(x = xc, y = yc,
       text = paste0(annotate$SNP,"<br>","GENE: ",annotate$GENE),
       font = list(family = "serif", size = 10))))

Q-Q Plot

  • The arguments snp = “SNP” and gene = “GENE” specify that we want to add snp and gene information to each point. This information is found in the columns names “SNP” and “GENE” in the HapMap dataset. See help(manhattanly) for a full list of options.

Similarly, we can create an interactive Q-Q plot using one command (See help(qqly) for a full list of options):

qqly(subset(HapMap, CHR %in% 4:7), snp = "SNP", gene = "GENE")

Volcano Plot

  • You can also make a volcano plot which by default, highlights the points greater than the default genomewideline and effect_size_line arguments:
volcanoly(subset(HapMap, CHR %in% 4:7), snp = "SNP", gene = "GENE")